﻿using DevExpress.Mvvm;
using DevExpress.XtraEditors;
using SX_MesProject.Dtos.WarehouseDTO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static SX_MesProject.HttpClientHelper;

namespace SX_MesProject.Warehouse
{
    public partial class WarehouseInfor : DevExpress.XtraEditors.XtraForm
    {
        public delegate Task LoadData();
        public event LoadData OnLoadData;
        public WarehouseInfor()
        {
            InitializeComponent();
        }

        private async void simpleButton1_Click(object sender, EventArgs e)
        {
            WarehouseInput input = new WarehouseInput();
            input.warehouseTypeId = (int)this.warehouseTypeId.EditValue;
            input.stackingTypeId = (int)this.lookUpEdit2.EditValue;
            input.warehouseNumber = this.textEdit3.Text;
            input.warehousePprefixDigits = this.textEdit4.Text;
            input.validIdentification = this.checkEdit1.Checked;
            input.firstInfirstout = this.checkEdit2.Checked;
            input.remarks = this.textEdit5.Text;
            input.createTime = DateTime.Now;

            var refult = await HttpClientHelper.RequestUrl<WarehouseInput, ApiResult<string>>("https://localhost:44556/", "AddWarehouse", MethodType.POST, input);
            if (refult.Code == 200)
            {
                MessageBox.Show("添加成功");
                OnLoadData?.Invoke();
                this.Close();
            }
            else
            {
                MessageBox.Show("添加失败");
                this.Close();
            }
        }

        private void panelControl1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void checkEdit1_CheckedChanged(object sender, EventArgs e)
        {

        }



        //private void lookUpEdit1_EditValueChanged(object sender, EventArgs e)
        //{

        //}


        private void WarehouseInfor_Load(object sender, EventArgs e)
        {
            GetwarehouseTypes();
            GetstackingTypes();

        }
        public async void GetwarehouseTypes()
        {
            string baseURL = "https://localhost:44556/";
            var method = "GetWarehousesType";
            var refult = await HttpClientHelper.RequestUrl<string, ApiResult<List<warehouseType>>>(baseURL, method, MethodType.GET, default);
            this.warehouseTypeId.Properties.DataSource = refult.Data;
            warehouseTypeId.Properties.DisplayMember = "warehouseTypeName";
            warehouseTypeId.Properties.ValueMember = "warehouseTypeId";

        }
        public async void GetstackingTypes()
        {
            string baseURL = "https://localhost:44556/";
            var method = "GetstackingType";
            var refult = await HttpClientHelper.RequestUrl<string, ApiResult<List<stackingType>>>(baseURL, method, MethodType.GET, default);
            this.lookUpEdit2.Properties.DataSource = refult.Data;
            lookUpEdit2.Properties.DisplayMember = "stackingTypeName";
            lookUpEdit2.Properties.ValueMember = "stackingTypeId";

        }

        private void warehouseTypeId_EditValueChanged(object sender, EventArgs e)
        {

        }
    }
}